package my.Interceptor.log;


import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class LogAdvice {

    @Pointcut("@within(my.Interceptor.log.Log)")
    private void advice() {
    }

   /* @Before("advice()")
    public void doBefore(JoinPoint jp) {
        String methodInfo = jp.getSignature().getName();;
        System.out.println("获取到："+methodInfo);
    }*/
    @Order(1)
    @Around(value="advice()")
    public Object aroundMethod_1(ProceedingJoinPoint point){
        Object result = null;
        String methodName = point.getSignature().getName();
        try {
        	System.out.println("拦截1");
            result = point.proceed();
            System.out.println("拦截1"+result);
        } catch (Throwable e) {
            System.out.println("this method "+methodName+" end.ex message<"+e+">");
            throw new RuntimeException(e);
        }
        return result;
    }
    @Order(2)
    @Around(value="advice()")
    public Object aroundMethod_2(ProceedingJoinPoint point){
    	Object result = null;
    	String methodName = point.getSignature().getName();
    	try {
    		System.out.println("拦截2");
    		result = point.proceed();
    		System.out.println("拦截2"+result);
    		Person person = (Person) result;
    		person.setWork("收钱");
    		result = person;
    	} catch (Throwable e) {
    		System.out.println("this method "+methodName+" end.ex message<"+e+">");
    		throw new RuntimeException(e);
    	}
    	return result;
    }
    
}
